#include "stdafx.h"
#include "CPlayer.h"
#include "Tools.h"

CPlayer::CPlayer()
{
	m_PosX = 10;
	m_PosY = 10;
	m_Speed = 1;
	m_Dir = 0;
	char filename[] = "pic/player0.png";
	for (int i = 0; i < 4; i++)
	{
		//sprintf_s(filename, "pic/player%d.png", i);
		filename[10] = '0' + i;
		m_Image[i] = cvLoadImage(filename);
	}

}


CPlayer::~CPlayer()
{
	for (int i = 0; i < 4; i++)
	{
		cvReleaseImage(&m_Image[i]);
	}
}

void CPlayer::Move(char key)
{
	switch (key)
	{
	case 'a':
		m_PosY -= m_Speed;
		m_Dir = 1;
		break;
	case 's':
		m_PosX += m_Speed;
		m_Dir = 0;
		break;
	case 'w':
		m_PosX -= m_Speed;
		m_Dir = 3;
		break;
	case 'd':
		m_PosY += m_Speed;
		m_Dir = 2;
		break;
	}
}

void CPlayer::Draw2Back(IplImage * pback)
{
	IplImage * currImg = m_Image[m_Dir];
	Copy2Back(currImg, pback,
		m_PosX, m_PosY, 235, 235, 235);
}


